package test;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description 三只小狗抢100根香肠，一次只能抢一根，直到抢完为止，统计每只小狗抢了多少
 * 一次只能抢一根
 * @Author Firenut
 * @Date 2023-09-04 14:07
 */
public class test3 {
    static AtomicInteger ge = new AtomicInteger(100);


    public static void main(String[] args) throws InterruptedException {
        Dog d1 = new Dog();
        Dog d2 = new Dog();
        Dog d3 = new Dog();


        Thread t1 = new Thread() {
            @Override
            public void run() {
                while (true) {
                    if (ge.get() == 0) {
                        break;
                    }
                    d1.getFood(ge);
                }
            }
        };

        Thread t2 = new Thread() {
            @Override
            public void run() {
                while (true) {
                    if (ge.get() == 0) {
                        break;
                    }
                    d2.getFood(ge);
                }
            }
        };

        Thread t3 = new Thread() {
            @Override
            public void run() {
                while (true) {
                    if (ge.get() == 0) {
                        break;
                    }
                    d3.getFood(ge);
                }
            }
        };

        t1.start();
        t2.start();
        t3.start();

        System.out.println(d1.count);
        System.out.println(d2.count);
        System.out.println(d3.count);
    }
}
